﻿/// <reference path="application.js" />

keyMap =
{
    Left: 37,
    Right: 39,
    Jump: 32, // Space bar
    CameraLeft: 100,
    CameraRight: 102,
    CameraUp: 104,
    CameraDown: 98,
    CameraTrack: 101,
    ViewFinderUp: 38, // up arrow
    ViewFinderDown: 40, // down arrow
    ToggleRope: 65 // a
};

function InputManager() {
    if (typeof InputManager.initialized == "undefined") {
        
        /// Handles key down
        InputManager.prototype.HandleKeyDown = function (event) {
            //alert(event.keyCode);
            var ignore = true;
            for (keyItem in keyMap) {
                if (keyMap[keyItem] == event.keyCode) {
                    app.input.key["is" + keyItem + "KeyPressed"] = true;
                    ignore = false;
                }
            }

            return ignore;
        };

        /// Handles key up
        InputManager.prototype.HandleKeyUp = function (event) {
            var ignore = true;
            for (keyItem in keyMap) {
                if (keyMap[keyItem] == event.keyCode) {
                    app.input.key["is" + keyItem + "KeyPressed"] = false;
                    ignore = false;
                }
            }

            return ignore;
        };

        /// Starts handling key events
        InputManager.prototype.Start = function () {
            window.onkeydown = this.HandleKeyDown;
            window.onkeyup = this.HandleKeyUp;
        };

        InputManager.initialized = true;
    }
};